package soa.security.web.support.action;

import javax.annotation.Resource;

import soa.security.mgr.service.base.BaseMgrService;
import v1.web.PageContext;
import v1.web.action.DefaultV1ModelAction;

/**
 * 项目内的所有基于V1风格开发的Action继承该类，项目可以根据需要将通用的方法写入此类中
 * 
 * @author wangs
 * @version 1.0
 * 
 * @param <T>
 */
public abstract class DefaultModelAction<T> extends
		DefaultV1ModelAction<T, String> implements DefaultOperationSupport {
	private static final long serialVersionUID = 8513904364342778749L;

	@Resource(name = "baseMgrServiceImpl")
	protected BaseMgrService baseMgrService;

	@Override
	protected PageContext<T> buildContext() {
		PageContext<T> vc = new PageContext<T>(this.getModel());
		return vc;
	}

	@Override
	public Class<String> getType() {
		return String.class;
	}

	@Override
	public String wrap(String _id) {
		return String.valueOf(_id);
	}

	/**
	 * 查询页面执行前，添加默认的属性
	 */
	public void prepareList() {
		if (page != null) {
			log.trace("初始化PageInfo属性");
			if (!page.hasOrder()) {
				page.addOrderDesc("id"); // 如果模型没有id，那么会报错，或者不需要根据id倒排，都可以覆盖此方法
			}
		}
	}

	@Override
	public String list() {
		return SUCCESS;
	}

	@Override
	public String done() {
		return SUCCESS;
	}

	@Override
	public String create() {
		return SUCCESS;
	}

	@Override
	public String update() {
		return SUCCESS;
	}

	@Override
	public String remove() {
		return SUCCESS;
	}

	@Override
	public String view() {
		return SUCCESS;
	}

	@Override
	public String edit() {
		updateResultContent(this.getModel());
		return SUCCESS;
	}
}